package com.xzsoft.gdwz.services.impl;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.xzsoft.gdwz.dao.UserTokenDao;
import com.xzsoft.gdwz.model.UserToken;
import com.xzsoft.gdwz.services.TokenServices;

@Service("tokenServices")
public class TokenServicesImpl implements TokenServices {
	@Resource
	private UserTokenDao userTokenDao;
	
	@Override
	public UserToken selectTokenByName(String name) {
		return userTokenDao.selectTokenByName(name);
	}

	@Override
	public void insertToken(UserToken token) {
		
	}

	@Override
	public void updateToken(Map map) {
		UserToken token = new UserToken();
		token.setEcommerceName((String)map.get("ecommerce_name"));
		token.setAccessToken((String)map.get("access_token"));
		token.setRefreshToken((String)map.get("refresh_token"));
		token.setTime((Long)map.get("time")+"");
		token.setExpiresIn((Integer)map.get("expires_in")+"");
		token.setRefreshTokenExpires((Long)map.get("refresh_token_expires")+"");
		System.out.println();
		userTokenDao.updateToken(token);
	}

	@Override
	public UserToken getToken(String id) {
		return null;
	}

	@Override
	public UserToken getTokenByName(String enName) {
		return userTokenDao.selectTokenByName(enName);
	}

	@Override
	public UserToken getToken(String username, String password) {
		return userTokenDao.selectTokenByPass(username,password);
	}
	
}
